#coding:utf-8
class HtmlOutputer:

    def __init__(self):
        self.datas = []

    def collect_data(self,data):
        if data is None:
            return
        self.datas.append(data)

    def output_html(self):
        ftext=open('output.txt','w',encoding='utf-8')
        for mdata in self.datas:
            ftext.write(mdata['title'])
            ftext.write(mdata['summary'])
            ftext.write("\n")
        ftext.close()



        fout = open('output.html','w',encoding='utf-8')

        fout.write("<html>")
        fout.write("<head>")
        fout.write("<meta http-equiv='Content-Type' content='text/html';charset='utf-8'>")
        fout.write("</head>")
        fout.write("<body>")
        fout.write("<table>")

        for data in self.datas:
            print(data['title'])
            fout.write("<tr>")
            fout.write("<td>%s</td>" % data['url'])
            fout.write("<td>%s</td>" % data['title'].encode('utf-8'))
            fout.write("<td>%s</td>" % data['summary'].encode('utf-8'))
            fout.write("</tr>")
        fout.write("</table>")
        fout.write("</body>")
        fout.write("</html>")

        fout.close()